import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.alibaba.fastjson.JSON;
import com.aliyun.odps.udf.UDF;
import com.aliyun.odps.utils.StringUtils;

public class SpliderBeautyExpertTitle extends UDF {

	/**
	 * 将title中包含的容量大小切割出来
	 * @return
	 */
	public String evaluate(String title) {
		Map<String, String> result = new HashMap<String, String>();
		if(StringUtils.isNotBlank(title)) {
			title = title.trim();
			//将标题按照空格切割 数组最后一个是否包含数字
			String[] split = title.split(" ");
			//正则匹配
			Pattern p = Pattern.compile(".*\\d+.*");
			Matcher matcher = p.matcher(split[split.length-1]);
			if(matcher.matches()) {
				//最后一个包含数字
				result.put("volume", split[split.length-1]);
				StringBuffer sb = new StringBuffer();
				for (int i = 0; i < split.length-1; i++) {
					sb.append(split[i]).append(" ");
				}
				result.put("title", sb.toString());
			}else {
				//不包含数字
				result.put("title", title);
			}
		}
		System.out.println(JSON.toJSONString(result));
		return JSON.toJSONString(result);
	}
}
